package com.yi.wood.service.impl;

import com.yi.wood.service.CommonService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;

/**
 * @author MoYi
 * create date 2019/4/14 11:25
 */
public abstract class AbstractCommonService<T> implements CommonService<T> {

    private JpaRepository<T, Long> repository;

    /**
     * 设置Dao实现
     * @param repository Dao实现
     */
    void setRepository(JpaRepository<T, Long> repository){
        this.repository = repository;
    }

    @Override
    public T addData(T t) {
        return repository.save(t);
    }

    @Override
    public T updateData(T t) {
        return repository.save(t);
    }

    @Override
    public void delData(Long id) {
        repository.deleteById(id);
    }

    @Override
    public Page<T> pageDataList(Example<T> example, Pageable pageable) {
        return repository.findAll(example, pageable);
    }
}
